Extract a Slicer / Parameter's members

{ getParameterElements }

Enumerates and returns the members/elements contained in a Formulation parameter - useful for building slicer lists outside of the application.

Method

/API2/query/getParameterElements

  • API Section: /API2/query
  • API Version: 2.0
  • From Release: 2018.5.2
  • Can be used by Non-admin accounts
  • Method operates via POST actions only.
  • Input Parameters

    Name

    parameterId

    Type

    string

    Description

    The parameter's system ID

    Output Response

    Successful Result Code

    200

    Response Type

    Description of Response Type

    successful operation

    Notes

    To use this function, create custom 'Lists' and 'Parameters' in the application. The resultset can then be used to drive external applications like filtering embedded content. The parameter's ID comes from the content manager inside the main client application.

    Examples
    Running Queries and Slicers programmatically (JavaScript):

    This example demonstrates how to run queries and slicers (parameters) programmatically to extract results.

    The example uses API authentication driven from JavaScript. See Authentication APIs for alternatives.

    // URL of the Pyramid installation and the path to the API 2.0 REST methods
    var pyramidURL = "http://mysite.com/api2/";
    
    
    // step 1: authenticate admin account and get token
    // NOTE: callApi method is a generic REST method shown below.
    let token = callApi("auth/authenticateUser",{
    	"data":{
    		"userName":"adminUser",
    		"password":"abc123!"
    	}
    },false);
    
    
    //step 2: find a parameter definition called "param x". Parameters are saved items to drive slicers
    let calculation = callApi("content/findContentItem",{
    	"searchParams": {
    		"searchString": "param x",
    		"filterTypes": [2],
    		"searchMatchType": 2,
    		"searchRootFolderType":0
    	},
    	"auth": token // admin token generated above
    });
    
    let paramId = calculation.data[0].id;
    
    //step 3: get the parameter's elements
    let parameterElements = callApi("query/getParameterElements ",{
       "parameterId": paramId,
       "auth": token
    });
    
    let members = parameterElements.data.members // list for members
    console.log(members);
    
    //step 4: find a data discovery called "report x"
    let dataDiscovery = callApi("content/findContentItem",{
    	"searchParams": {
    		"searchString": "report x",
    		"filterTypes": [3],
    		"searchMatchType": 2,
    		"searchRootFolderType":0
    	},
    	"auth": token // admin token generated above
    });
    
    
    let reportId = dataDiscovery.data[0].id;
    
    //step 5: extract the report results as JSON that have been filtered by the first member of the parameter found in step 3
    let queryResult = callApi("query/extractQueryResult ",{
       "data": {
          "itemId":reportId,
          "exportType":0, //JSON
          "exportOptions": {},
          "externalParameters": {
            "reportFilters" : [
             {
             "value": members[0].uniqueName
             }
            ]
          }
       },
       "auth": token
    });
    
    console.log(JSON.parse(queryResult.data));
    
    
    // ##### optional generic logging method for debugging ##############
    function log(msg){
    	document.write(msg);
    	console.log(msg);
    }
    
    // ##### generic REST API calling method ##############
    function callApi(path,data,parseResult=true){
    	var xhttp = new XMLHttpRequest();
    	xhttp.open("POST", pyramidURL+path, false);
    	xhttp.send(JSON.stringify(data));
    	if(parseResult){
    		return JSON.parse(xhttp.responseText);
    	}else{
    		return xhttp.responseText;
    	}
    }